package mn.idax.exchange.otc.common.mq.sqs;

import com.alibaba.fastjson.JSON;
import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.sqs.AmazonSQS;
import com.amazonaws.services.sqs.AmazonSQSClientBuilder;
import com.amazonaws.services.sqs.model.CreateQueueRequest;
import com.amazonaws.services.sqs.model.SendMessageRequest;

/**
 * 功能描述: 亚马逊sqs消息发送
 *
 * @auther: zengli
 * @date: 2018/10/18
 */
public class SqsUtil {

    private static AmazonSQS sqs;

    static {
        sqs = AmazonSQSClientBuilder.standard().withCredentials(new ClasspathPropertiesFileCredentialsProvider()).withRegion(Regions.AP_NORTHEAST_1).build();
    }

    private SqsUtil() {
    }

    /**
     * 功能描述: 创建队列
     *
     * @param: queueName 队列名
     * @auther: zengli
     * @date: 2018/10/18
     */
    public static void createQueue(String queueName) {
        CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName);
        sqs.createQueue(createQueueRequest);
    }

    /**
     * 功能描述: 发消息
     *
     * @param: [queueName 队列名, message 消息类容]
     * @auther: zengli
     * @date: 2018/10/18
     */
    public static void sendMessage(String queueName, String message) {
        String queueUrl = sqs.getQueueUrl(queueName).getQueueUrl();
        SendMessageRequest request = new SendMessageRequest();
        request.withQueueUrl(queueUrl);
        request.withMessageBody(message);
        sqs.sendMessage(request);
    }

    public static void main(String[] args) {
        SqsUtil.sendMessage("Debug_Notity","jension test");
    }

}